<template>
    <div class="trace">
        <div  class="item">
            <div class="left-content">
                <div class="head-img" v-if="model.imgurl">
                        <img  :src="model.imgurl" alt="">
                </div>
                <div class="head-img" v-else >
                        <img  src="../../assets/avatar2.png" alt="">
                </div>
                <div class="head-info">
                    <h3>{{model.userName}}</h3>
                    <p>{{model.age}} | {{model.DepartName}}</p>
                </div>
            </div>
            <div class="right-content">
                <p class="date" style="color: red;font-weight: bold;text-align: right;">体温:{{model.Temperature}} &#8451</p>
                <p>{{model.RegistDate.substr(0,16)}}</p>
            </div>
        </div>
        <div class="sift">
            <h3 class="header">异常情况</h3>
            <div class="c-item" v-for="(item, index) in listArr" :key="index">
                    <input style="margin-top: 20px;" :readonly="!isCanEdit" type="checkbox" name="check"  :value="item"  v-model="checklist">
                    <div class="name">
                        {{item}}
                    </div>
            </div>

        </div>
        <div class="sift">
            
            <div  class="trace-detail">
                <div class="c-item">
                    <p class="title">采取措施</p>
                <div class="name">
                    <group>
                        <popup-picker :disabled="!isCanEdit" :data="list2" v-model="value3" placeholder="点击选择"></popup-picker>
                    </group>
                </div>
                </div>
                <div class="c-item">
                    <p class="title">登记日期</p>
                    <div class="name">
                        {{model.RegistDate.substr(0,16)}}
                    </div>
                </div>
            </div>
        </div>
        <div class="sift menu">
            <div class="btns" v-if="isCanEdit">
                <!-- <div class="save">保存</div> -->
                <div class="submit" @click="toSubmit">提交</div>
            </div>
        </div> 
        <myMenu ></myMenu>
    </div>
</template>

<script>
import { XSwitch, Group, InlineXSwitch, XNumber, Datetime, XAddress, ChinaAddressV4Data, Value2nameFilter as value2name, PopupPicker } from 'vux'
import Upload from '@commonComponents/upload/index'
import formatDate from "@/utils/formatDate"
import myMenu from '@/commonComponents/menu'
export default {
    name: 'trace',
    data () {
        return {
            isCanEdit: true, // 是否可以编辑
            userInfo: {},
            addressData: ChinaAddressV4Data,
            temperature: 36.2, // 体温
            model:{
                RegistDate:`${formatDate().split('-')[0]}-${formatDate().split('-')[1]}-${formatDate().split('-')[2]} ${formatDate().split('-')[3]}:${formatDate().split('-')[4]}`,
            },
            listArr:[],
            value3: [],
            parmas: {
                TemperatureId:"",
            },
            checklist:[],
            formData: '',
            images: [],
            uploadLength: 0, // 图片上传个数
            list2: [],
        }
    },
    components: {
        XSwitch,
        Group,
        InlineXSwitch,
        XNumber,
        Datetime,
        XAddress,
        PopupPicker,
        Upload,
        myMenu
    },
    created () {
        this.$vux.loading.show({
            text: '加载中...'
        })
        // 获取用户信息，判断是否有操作权限
        this.userInfo = JSON.parse(localStorage.getItem('registerInfo')) || {}
        this.$axiosAjax.GetIsManager({
            userNo: this.userInfo.userId
        }).then(res => {
            if (res.status == 200) {
                if (res.data.code == 1) {
                    this.isCanEdit = true
                } else {
                    this.isCanEdit = false
                }
            }
        })
    },
    mounted () {
        this.GetSymptom()
        this.GetDealInfo()
        if(this.$route.query.tempid !=''  && typeof(this.$route.query.tempid) !='undefined')
        {
           this.getmodel(this.$route.query.tempid);
        }
    },
    methods: {
        setFormData (formData, uploadLength, images) {
            console.log(222,formData,uploadLength,images);
            this.formData = formData
            this.uploadLength = uploadLength
            this.images = images
        },
        getmodel (id) {
            this.parmas.TemperatureId = id
            this.$axiosAjax.GetTemperatureHighById(this.parmas).then((res) => {
                if (res.status == 200) {
                    this.$vux.loading.hide();
                    this.model = res.data.data
                    if(this.model.BodyCondition!='') {
                        this.checklist = this.model.BodyCondition.split(',')
                    }
                    if(this.model.DealInfo!='') {
                        this.value3 = this.model.DealInfo.split(',') 
                    }
                    
                }
            })
        },
        toSubmit() {
            if (this.checklist.length==0) {
                this.$vux.toast.text('异常情况不能为空');
                return;
            }
            if (this.value3.length==0) {
                this.$vux.toast.text('采取措施不能为空');
                return;
            }
            this.$vux.loading.show({
                text: '正在提交...'
            });
            let params = {
                'BodyCondition': this.checklist.join(','),
                'Temperature': this.model.Temperature,
                'DealInfo': this.value3.join(','),
                'RegistDate': this.model.RegistDate,
                'TemperatureId': this.parmas.TemperatureId
            }
            this.$axiosAjax.PostSaveSingleData(
                params
            ).then((res) => {
                if (res.data.code === 0) {
                    this.$vux.loading.hide();
                    this.$vux.toast.text('提交成功')
                    this.$router.go(-1)
                } else {
                    this.$vux.toast.text('提交失败')
                }
            }).catch(() => {
                this.$vux.toast.text('提交失败')
            })
        },
        GetSymptom () {
            this.$axiosAjax.GetSymptom().then((res) => {
                if (res.status == 200) {
                    this.listArr = res.data
                }
            })
        },
        GetDealInfo () {
            this.$axiosAjax.GetDealInfo().then((res) => {
                if (res.status == 200) {
                    let cateList = res.data
                    this.list2.push(cateList)
                }
            })
        },
    }
}
</script>

<style lang="less" scoped>
    .trace {
        .item {
            background-color: #fff;
            padding: 10px;
            height: 80px;
            overflow: hidden;
            display: flex;
            justify-content: space-between;
            border-bottom: 1px solid #f2f2f2;
            .left-content {
                position: relative;
                flex: 3;
                font-size: 14px;
                .head-img {
                    width: 40px;
                    height: 40px;
                    border-radius: 50%;
                    border: 1px solid #eee;
                    position: absolute;
                    left: 0;
                    top: 50%;
                    transform: translateY(-50%);
                    img {
                        width: 100%;
                        height: 100%;
                    }
                }
                .head-info {
                    height: 100%;
                    position: absolute;
                    left: 50px;
                    top: 50%;
                    transform: translateY(-50%);
                    padding: 10px 0;
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;
                    h3 {
                        font-weight: bold;
                    }
                    p {
                        width: 45.333vw;
                        white-space: nowrap;
                        overflow: hidden;
                        text-overflow: ellipsis;
                    }
                }
            }
            .right-content {
                font-size: 14px;
                padding: 10px;
                display: flex;
                flex-direction: column;
                justify-content: space-between;
                .date {
                    color: #666;
                    padding-bottom: 5px;
                }
                .trace {
                    font-size: 12px;
                    color: #2269FC;
                    border: 1px solid #2269FC;
                    background-color: #DAE6FE;
                    height: 28px;
                    line-height: 28px;
                    text-align: center;
                    border-radius: 14px;
                }
            }
        }
        background-color: #EBEEF2;
        .c-item {
            height: 50px;
            line-height: 50px;
            padding: 0 20px;
            display: flex;
            justify-content: space-between;
            border-bottom: 1px solid #f3f3f3;
            background-color: #fff;
            .name {
                text-align: right;
                .inline-x-switch {
                    top: 9px
                }
                .weui-switch:checked {
                    border-color: #2269FC;
                    background-color: #2269FC
                }
                input {
                    text-align: right;
                    &::-webkit-input-placeholder { /* WebKit browsers */
                        direction: rtl;
                        font-size: 16px;
                    }
                    &::-moz-placeholder { /* Mozilla Firefox 4 to 18 */
                        direction: rtl;
                        font-size: 16px;
                    }
                    &::-moz-placeholder { /* Mozilla Firefox 19+ but I'm not sure about working */
                        direction: rtl;
                        font-size: 16px;
                    }
                    &::-ms-input-placeholder { /* Internet Explorer 10+ */
                        direction: rtl;
                        font-size: 16px;
                    }
                }
            }
            .title {
                .red {
                    color: red;
                }
            }
        }
        .sift {
            margin-top: 15px;
            background-color: #fff;
            &.menu {
                border-bottom: 1px solid #f3f3f3;
            }
            .header {
                color: #2269FC;
                font-size: 14px;
                height: 50px;
                line-height: 50px;
                padding-left: 20px;
                font-weight: bold;
                border-bottom: 1px solid #f3f3f3;
                position: relative;
                .add-trace {
                    display: inline-block;
                    width: 80px;
                    height: 30px;
                    line-height: 30px;
                    font-size: 12px;
                    text-align: center;
                    color: #2269FC;
                    border: 1px solid #2269FC;
                    border-radius: 15px;
                    position: absolute;
                    top: 10px;
                    right: 20px;
                }
            }
            .trace-detail {
                .header {
                    &.item {
                        border-bottom: none;
                        padding-left: 30px;
                    }
                }
            }
            .fujian {
                padding: 20px;
                .left {
                    font-weight: bold;
                }
                .right {
                    float: right;
                }
            }
            .upload-wrap {
                padding: 0 20px 20px 20px;
            }
            .btns {
            width: 100%;
            display: flex;
            justify-content: center;
            background-color: #fff;
            .save, .submit {
                width: 150px;
                height: 40px;
                line-height: 40px;
                border-radius: 20px;
                text-align: center;
                color: #fff;
                background-color: #2269FC;
            }
            .submit {

            }
        }
        }
    }
</style>

<style lang="less">
 .trace {
    .name {
        div:first-of-type {
            height: 100%;
        }
        .weui-cells {
            height: 100%;
            margin-top: 0 !important;
            &::before, &::after {
                border: none;
            }
            .weui-cell {
                padding-right: 0;
                .weui-cell__ft {
                    height: 30px;
                    .vux-number-selector {
                        &.vux-number-selector-plus {
                            margin-right: 0;
                        }
                        height: 100%;
                        background-color: #DAE6FE;
                        svg {
                            fill: #2269FC;
                        }
                    }
                    .vux-cell-value {
                        height: 100%;
                        display: inline-block;
                        padding-top: 5px;
                    }
                    .vux-number-input {
                        height: 100%;
                    }
                }
            }
        }
    }
 }
 
.vux-popup-dialog {
    height: 300px !important;
}
</style>